<%@ page language="java" contentType="text/html;charset=UTF-8" %>
<%@ include file="/static/include/taglib.jsp" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html >
<html>
<head>
    <meta name="viewport" content="width=device-width"/>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <title>队伍管理--机构列表</title>
    <link href="${ctxStatic}/layui/css/layui.css" rel="stylesheet"/>
    <%--<link href="${ctxStatic}/css/kpiuitanchu.css" rel="stylesheet"/>--%>
    <link href="${ctxStatic}/ligeruilib/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css">
    <link href="${ctxStatic}/css/kpiui.css" rel="stylesheet"/>
    <script src="${ctxStatic}/js/jquery-1.8.3.min.js?v=2.0" type="text/javascript"></script>
    <script src="${ctxStatic}/layui/layui.all.js" type="text/javascript"></script>
    <script src="${ctxStatic}/ligeruilib/ligerUI/js/core/base.js" type="text/javascript"></script>
    <script src="${ctxStatic}/ligeruilib/ligerUI/js/plugins/ligerGrid.js" type="text/javascript"></script>
    <script src="${ctxStatic}/ligeruilib/ligerUI/js/plugins/ligerTree.js" type="text/javascript"></script>
    <script src="${ctxStatic}/ligeruilib/ligerUI/js/plugins/ligerComboBox.js" type="text/javascript"></script>
    <script src="${ctxStatic}/js/common.js" type="text/javascript"></script>

    <style>

        .button {
            border: 1px solid #589df5;
            height: 30px;
            line-height: 30px;
            min-width: 80px;
            cursor: pointer;
            box-shadow: 0px 0px 2px 2px #0b6e94;
            background-color: none;
            background: transparent;
            color: #ffffff;

        }
    </style>
</head>
<body>
<form>
    <div class="tanchucontent">
        <div style="width:90%;margin:0 auto">
            <div id="orgsuylist" class="list" lay-filter="orgsuylist"></div>

            <div style="width:100%;text-align: right;margin-top:15px">
                <input type="button" class="button" value="保存" id="btnsave"/>
                <input type="button" class="button" value="关闭" onclick="top.CloseOpenWindow()"/>
            </div>

            <input type="hidden" id="templateid" value="${templateid}">
        </div>
    </div>
</form>
<script>


    $(function () {

        getCheck();
    })
    var table;
    var funcData = [];//这里存放你从后台拿到的要默认勾选的数据，现在这里是空的，需要你自己去获取数据

    function getData(id) {


        for (var i = 0; i < funcData.length; i++) {

            if (funcData[i].orgid == id) {

                if (funcData[i].tempid != null && funcData[i].tempid != 'null') {
                    return true
                } else {
                    return false
                }

            }
        }
    }


    function f_isChecked(rowdata) {

        return getData(rowdata.orgid);
    }

    function getCheck() {


        $.ajax({
            type: "POST",
            url: "get_CheckorgList",
            data: {templateid: $('#templateid').val()},
            beforeSend: function (XHR) {

            },
            success: function (data) {

                data = eval('(' + data + ')');
                funcData = data;
                var checkRow = [];
                for (var i = 0; i < data.length; i++) {

                    var element = data[i];

                    if (element.tempid) {
                        checkRow.push(element.orgid);
                        $("#orgsuylist").ligerGrid("select", element.orgid);
                    }

                }
                $("#orgsuylist").ligerGrid("selectNode", checkRow);
                treeList();
                // f_isChecked();
            },
            complete: function (XHR) {

            },
            error: function () {

            }
        });
    }

    function treeList() {
        $("#orgsuylist").ligerGrid({
            checkbox: true,
            columns: [

                //{ display: '序号', width: 80, name: 'rowNum' },
                {display: '机构名称', width: 400, align: 'left', name: 'orgname', id: "orgname"},


            ],
            pageSize: 30,
            url: "get_orgList",
            delayLoad: false,            //初始化时是否加载,为true时,不加载,为false时,则加载
            sortName: null,
            dataAction: 'server',
            parms: {},
            sortOrder: null,
            // sourceObj: _this.grid,
            root: 'items',                       //数据源字段名
            record: 'countRecord',                    //数据源记录数字段名
            pageParmName: 'CurrentPage',               //页索引参数名，(提交给服务器)
            pagesizeParmName: 'PageSize',        //页记录数参数名，(提交给服务器)
            data: {},
            width: "100%",
            height: '90%',
            heightDiff: 0,
            rowHeight: 28,
            isChecked: f_isChecked,
            onBeforeCheckRow: function (checked, data, rowid, rowdata) {

            },
            onBeforeCheckAllRow: function (checked, element) {
                //alert(checked);
                // return false;
            },
            onSuccess: function (rowdata, rowindex) {

            },
            alternatingRow: true,
            border: 0,
            usePager: false,
            tree: {
                columnId: "orgname",
                idField: "orgid",
                parentIDField: "orgparentid"

            }
        })
    }


    layui.use(['form', 'table'], function () {
        var form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功
        table = layui.table;


        $("#btnsave").click(function () {


            var rows = $("#orgsuylist").ligerGrid().getSelecteds();
            var orgids = "";
            for (var i = 0; i < rows.length; i++) {
                orgids += rows[i].orgid + ",";
            }


            if (orgids.indexOf(",") <= 0) {
                alert('请选择部门');
                return;
            }
            var templateid = $("#templateid").val();
            top.frames["iframe"].vBTemplate.addentityuserusass(templateid, orgids);
        })

        form.on('checkbox(allChoose)', function (data) {
            var child = $("#userusasstempeditlist").find('tbody input[type="checkbox"]');
            child.each(function (index, item) {
                item.checked = data.elem.checked;
            });
            form.render('checkbox');
        });
        form.render();

    });
</script>
</body>
</html>